// =================================================================================================
//
//	CopyEngine Framework
//	Copyright 2012 Eran. All Rights Reserved.
//
//	This program is free software. You can redistribute and/or modify it
//	in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================

package copyengine.xflDecode
{
    public class XFLAnalysisUtils
    {
        public function XFLAnalysisUtils()
        {
        }

        /**
         * 取得当前节点的子节点
         *
         * XFL格式的节点结构格式如下:
         *
         * <DOMSymbolInstance>
         *     <matrix>
         *         <Matrix a="0.33333".../>
         *     </matrix>
         * </DOMSymbolInstance>
         *
         * 所以要通过CurrentNode(DOMSymbolInstance)取得其子节点(Matrix)都是通过
         * _currentNode.children()[0].children() 的方式取得
         *
         * 如果有该Property有多个节点则设置_isSingleProperty=false 这样返回一个XMLList包含所有的节点
         * 否则返回一个单节点的XML
         *
         */
        public static function getPropertyNode(_currentNode:XML, _nodeName:String, _isSingleProperty:Boolean = true):*
        {
            if (_currentNode != null)
            {
                var nodeList:XMLList = _currentNode.children();
                var subNodeLength:int = nodeList.length();
                for (var nodeIndex:int = 0; nodeIndex < subNodeLength; nodeIndex++)
                {
                    var subNode:XML = nodeList[nodeIndex];
                    if (subNode.localName() == _nodeName)
                    {
                        if (_isSingleProperty)
                        {
                            //XML
                            return subNode.children()[0];
                        }
                        else
                        {
                            //XMLList
                            return subNode.children();
                        }
                    }
                }
            }
        }

    }
}
